package objects;

import java.util.ArrayList;

import common.LoadingData;

public class Cell
{

    private short guid;
    private boolean walkable, LoS;
    private int itemID;
    private ArrayList<Long> monsterGroups = new ArrayList<Long>(); 

    public Cell() {
    }

    public Cell(short id, boolean pWalkable, boolean pLoS, int pItemID) {
    	
        //GameServer.writeLine("Cell " + id + " walakable : " + walkable + " LoS " + LoS + " item : " + itemID);
        guid = id;
        walkable = pWalkable;
        LoS = pLoS;
        itemID = pItemID;
    }

    public static int getIntByHashedValue(char c) {
        char[] HASH = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
            't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
            'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'};
        for (int a = 0; a < HASH.length; a++) {
            if (HASH[a] == c) {
                return a;
            }
        }
        return -1;
    }

    public static short decodeCellID(String cellCode) {
        char[] HASH = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
            't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
            'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'};
        char char1 = cellCode.charAt(0), char2 = cellCode.charAt(1);
        int code1 = 0, code2 = 0, a = 0;
        while (a < HASH.length) {
            if (HASH[a] == char1) {
                code1 = a * 64;
            }
            if (HASH[a] == char2) {
                code2 = a;
            }
            a++;
        }
        return Short.parseShort(Integer.toString((code1 + code2)));
    }

    public static String encodeCellID(int cellID) {
        char[] HASH = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
            't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
            'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'};

        int char1 = cellID / 64, char2 = cellID % 64;
        return HASH[char1] + "" + HASH[char2];
    }

    public static Trigger getCellAction(int mapID, short cellID) {
        return LoadingData.getMapData().get(mapID).getTriggersDatas().get(cellID);
    }

	public short getGuid() {
		return guid;
	}

	public void setGuid(short guid) {
		this.guid = guid;
	}

	public boolean isWalkable() {
		return walkable;
	}

	public void setWalkable(boolean walkable) {
		this.walkable = walkable;
	}

	public boolean isLoS() {
		return LoS;
	}

	public void setLoS(boolean loS) {
		LoS = loS;
	}

	public int getItemID() {
		return itemID;
	}

	public void setItemID(int itemID) {
		this.itemID = itemID;
	}
	
	public ArrayList<Long> getMonsterGroups()
	{
		return monsterGroups;
	}
	
	public void addMonsterGroups(long groupID)
	{
		this.monsterGroups.add(groupID);
	}
	
	public void deleteMonsterGroups(long groupID)
	{
		this.monsterGroups.remove(groupID);
	}
	
}